import itertools

# 计数器
counter = itertools.count(10)
print("从10开始的计数:")
for i in range(3):
    print(next(counter))

# 循环迭代器
cycler = itertools.cycle("ABC")
print("循环重复:")
for i in range(5):
    print(next(cycler))

# 重复迭代器
repeater = itertools.repeat("hello", 3)
print("重复元素:", list(repeater))


# 累积和
print("累积和:", list(itertools.accumulate([1, 2, 3, 4, 5])))

# 链式连接
print("链式连接:", list(itertools.chain("ABC", "DEF")))

# 分组
data = ["A", "A", "B", "C", "C", "C"]
print("分组:")
for key, group in itertools.groupby(data):
    print(f"{key}: {list(group)}")


# 排列
print("排列:", list(itertools.permutations("ABC", 2)))

# 组合
print("组合:", list(itertools.combinations("ABC", 2)))

# 带重复的组合
print("带重复的组合:", list(itertools.combinations_with_replacement("ABC", 2)))


# 并行迭代
names = ["Alice", "Bob", "Charlie", "susan"]
ages = [25, 30, 35]
for name, age in itertools.zip_longest(names, ages, fillvalue="未知"):
    print(f"{name}: {age}岁")
